<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');
header('Content-Type: application/xml; charset=UTF-8');

$daytime = strtotime(date('Y-m-d'));
$condition = array( 
		'team_type' => 'normal',
		"begin_time <= {$daytime}",
		"end_time > {$daytime}",
		);

$teams = DB::LimitQuery('team', array(
			'condition' => $condition,
			'order' => 'ORDER BY sort_order DESC, id DESC',
			));

$oa = array();
$si = array(
	'sitename' => $INI['system']['sitename'],
	'wwwprefix' => $INI['system']['wwwprefix'],
	'imgprefix' => $INI['system']['imgprefix'],
);



foreach($teams AS $one) {
    $city = Table::Fetch('category', $one['city_id']);
	$group = Table::Fetch('category', $one['group_id']);
	$partner = Table::Fetch('partner', $one['partner_id']);
	$area = Table::Fetch('area', $one['area_id']);
	$urloutput .= "<url>";
        $urloutput .= "<loc>{$si['wwwprefix']}" . "/team.php?id={$one['id']}</loc>";
    	if($city['name']){
    	    $urloutput .= "<city>{$city['name']}</city>";
    	}else {
    	    $urloutput .= "<city>全国</city>";
    	}
    	$urloutput .= "<title><![CDATA[{$one['title']}]]></title>";
    	$urloutput .= "<image>{$si['imgprefix']}"  . "/static/" . "{$one['image']}</image>";
    	$urloutput .= "<tag>{$group['name']}</tag>";
    	$urloutput .= "<startTime>{$one['begin_time']}</startTime>";
    	$urloutput .= "<endTime>{$one['end_time']}</endTime>";
    	$urloutput .= "<value>{$one['market_price']}</value>";
    	$urloutput .= "<price>{$one['team_price']}</price>";
    	$urloutput .= "<bought>{$one['now_number']}</bought>";
    	$urloutput .= "<shop><![CDATA[{$partner['title']}]]></shop>";
    	$urloutput .= "<addr><![CDATA[{$partner['address']}]]></addr>";
    	$urloutput .= "<area>{$area['name']}</area>";
    	$urloutput .= "<longitude></longitude>";
    	$urloutput .= "<latitude></latitude>";
	$urloutput .= "</url>";
}

$encode = 'utf-8';
$xmloutput = <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<urlset>
    <website>{$INI['system']['sitename']}</website>
	<siteurl>{$INI['system']['wwwprefix']}</siteurl>
    {$urloutput}
</urlset>
XML;
echo $xmloutput;


